package com.x.ant.manage;

import com.x.ant.dao.LineDao;
import com.x.ant.model.*;
import com.x.framework.manage.BaseManage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TaskManage extends BaseManage {
    @Autowired
    private LineDao lineDao;

    public void insertTask(Task task) throws Exception {
        task.setTaskCreateTime(this.getDate(0));
        Sender senderSet = new Sender();
        senderSet.setSenderLastDest(task.getTaskUnloadingArea() + "-" + task.getTaskUnloadingAddress());
        senderSet.setSenderLastGood(task.getTaskGoodsStandard());
        Sender senderWhere = new Sender();
        senderWhere.setUserId(task.getTaskSenderUserId());
        this.update(senderSet, senderWhere);
        this.insert(task);
    }

    public void updateTask(Task task) throws Exception {
        String taskSenderUserId = task.getTaskSenderUserId();
        String taskUnloadingArea = task.getTaskUnloadingArea();
        if(this.isString(taskSenderUserId) && this.isString(taskUnloadingArea)) {
            Sender senderSet = new Sender();
            senderSet.setSenderLastDest(taskUnloadingArea + "-" + task.getTaskUnloadingAddress());
            senderSet.setSenderLastGood(task.getTaskGoodsStandard());
            Sender senderWhere = new Sender();
            senderWhere.setUserId(taskSenderUserId);
            this.update(senderSet, senderWhere);
        }
        this.update(task);
    }

}